package com.pwser.consumer.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RetryRule;

@Configuration
public class RestTemplateRibbonConfig {
	
	@Bean
	@LoadBalanced //Netflix Ribbon实现客户端负载均衡的注解
	public RestTemplate getRestTemplate() {
		return new RestTemplate();
	}
	
	/**
	 * 自定义ribbon负载均衡算法
	 */
	@Bean
	public IRule getMyRule() {
		//return new RandomRule(); //同随机算法替换原有的轮询算法
		return new RetryRule(); //如果某个微服务访问不通，重试几次后（大约5-10次）将不再调用该服务
		//return new MyRule();
	}

}